package com.cby.web.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CustomExceptionHandler implements HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest,
                                         HttpServletResponse httpServletResponse, Object o, Exception e) {
        if(e instanceof NumberFormatException) {
            return new ModelAndView("number");
        }else if(e instanceof NullPointerException) {
            return new ModelAndView("error");
        }
        System.out.println(e.getCause().toString());
        return new ModelAndView("error");
    }
}
